package com.example.hello.exception;

import com.example.common.utils.result.ResultBO;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.AuthenticationException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * <p>
 *
 * </p>
 *
 * @author 12071
 * @date 2022/8/1 16:16
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResultBO handleException(Exception e) {
        log.error("?????????? 系统异常: {}", e.getMessage());
        return ResultBO.error(e.getMessage()) ;
    }

    @ExceptionHandler(AuthenticationException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResultBO handleAuthenticationException(Exception e) {
        log.error("?????????? 登录异常: {}", e.getMessage());
        return ResultBO.error(e.getMessage()) ;
    }
}
